﻿// ==========================================================================
// ConnectorWarningOut.cs
// Silverlight Shapes Library
// ==========================================================================
// Copyright (c) Silverlight Shapes Development Group
// All rights reserved.
// ==========================================================================

using System.Collections.Specialized;
using SD.Shapes.Common.Connections;
using SD.Utils.Windows;

namespace SD.Shapes.Samples.Connectors
{
    /// <summary>
    /// Defines a custom output connector that shows a warning.
    /// </summary>
    public sealed class ConnectorWarningOut : Connector
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectorWarningOut"/> class.
        /// </summary>
        public ConnectorWarningOut()
        {
            Connections.CollectionChanged += new NotifyCollectionChangedEventHandler(Connections_CollectionChanged);
        }

        private void Connections_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (IConnection connection in e.NewItems)
                {
                    if (connection.Sink.Connector == this)
                    {
                        ErrorWindow.Show("Warning: You connected a connection to a output port.");
                    }
                }
            }
        }
    }
}
